package com.avic.rong.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.fragment.collect.ArticleFragment;
import com.avic.rong.fragment.collect.QuestAnswerFragment;
import com.avic.rong.fragment.collect.GoodsFragment;
import com.avic.rong.fragment.collect.StandardFragment;
import com.flyco.tablayout.SlidingTabLayout;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//我的收藏
public class CollectionActivity extends BaseActivity {


    @BindView(R.id.tablayout_collect)
    SlidingTabLayout mTab;
    @BindView(R.id.vp_collect)
    ViewPager mVp;

    private String[] titles = {"标准", "商品", "文章", "问答"};

    private ArrayList<Fragment> fragments = new ArrayList<>();


    @Override
    protected int getContentViewId() {
        return R.layout.activity_collection;
    }

    @Override
    protected void initView() {
        tvTitle.setText("我的收藏");

        fragments.add(StandardFragment.getInstance(titles[0], context));
        fragments.add(GoodsFragment.getInstance(titles[1], context));
        fragments.add(ArticleFragment.getInstance(titles[2], context));
        fragments.add(QuestAnswerFragment.getInstance(titles[3], context));

        MyPageAdapter myPageAdapter = new MyPageAdapter(getSupportFragmentManager());
        mVp.setAdapter(myPageAdapter);
        mVp.setOffscreenPageLimit(fragments.size());
        mTab.setViewPager(mVp);

        mVp.setCurrentItem(0);
    }

    @Override
    protected void addListener() {
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    public class MyPageAdapter extends FragmentPagerAdapter {
        public MyPageAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return fragments.get(i);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }

    public static Intent queryIntent(Context context) {
        Intent intent = new Intent(context, CollectionActivity.class);
        return intent;
    }

}
